Skip to content

solution#502

Open
nastia7408 wants to merge 3 commits intomate-academy:masterfrom
nastia7408:develop
Open

solution#502
nastia7408 wants to merge 3 commits intomate-academy:masterfrom
nastia7408:develop

Conversation

@nastia7408
Copy link
Copy Markdown

No description provided.

Copy link
Copy Markdown

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Summary

This submission requires changes because the main feature of the task—implementing CRUD functionality for categories—has not been started. The code appears to be from the previous lesson without the required updates. You'll need to create a Category model, add the API endpoints for it in src/createServer.js, and update the Expense model to use a foreign key to link to a category.

Additionally, the build is failing due to a database error. The Expense model is trying to reference a users table, but the User model creates a Users table (with a capital 'U'). In PostgreSQL, these names are case-sensitive. You can fix this by updating the reference in your Expense model:

// src/models/Expense.model.js
userId: {
  type: DataTypes.INTEGER,
  references: {
    model: 'Users', // <-- Change this from 'users' to 'Users'
    key: 'id',
  },
  // ...
},

Please implement the category management feature and apply this fix to get the tests passing.


✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨

Important

Fix the issues, commit the changes, and then re-request my review using the Re-request review button2 in the Reviewers tab.

Tip

If you have any comments about this review, please leave a message in the Add a comment section below and mention me with the @mateacademy-ai-mentor tag3.
I will read your message during my next review of your pull request. Please do not reply directly to my comments, as that feature is not supported yet.

Caution

Do not close the pull request until the review is complete. Closing it early can lead to unexpected behavior and disrupt the review process.

Footnotes

  1. Rate AI review example

  2. Re-request AI review example

  3. Add AI review comments example

Comment thread src/models/Expense.model.js Outdated
Comment on lines +17 to +20
category: {
type: DataTypes.STRING,
allowNull: true,
},
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To enable CRUD functionality for categories as required by the task, Category should be implemented as a separate model. Consequently, this Expense model should reference a category via a foreign key (e.g., categoryId) rather than using a simple string field. This architectural change is essential for managing categories independently.

Comment thread src/createServer.js
return app;
};

module.exports = { createServer };
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The task requires implementing CRUD functionality for categories. This would involve creating a Category model, importing it here, and then adding the corresponding API endpoints (e.g., GET, POST, PATCH, DELETE for /categories) within this file. This implementation is currently missing.

Comment thread src/models/models.js
Comment on lines +9 to 18
const models = {
User,
Expense,
};

module.exports = {
models: {
User,
Expense,
},
models,
User,
Expense,
};
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To meet the task requirements, a Category model needs to be created and integrated here. You should import the Category model, define its relationship with Expense (e.g., an Expense belongs to a Category), and add it to the models object and the exports.

Copy link
Copy Markdown

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Summary

Great work on implementing the category management feature! You've successfully set up the new models, associations, and API endpoints, addressing all previous feedback.

However, a change is needed before this can be approved. In src/index.js, the server is being started twice. The initial createServer().listen(5700, ...) call at the top of the file is redundant and can cause port conflicts and unpredictable application behavior.

Please remove this block. The server should only be started once, inside the async function start(), after the database connection is confirmed. Once that's fixed, your work will be ready!


✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨

Important

Fix the issues, commit the changes, and then re-request my review using the Re-request review button2 in the Reviewers tab.

Tip

If you have any comments about this review, please leave a message in the Add a comment section below and mention me with the @mateacademy-ai-mentor tag3.
I will read your message during my next review of your pull request. Please do not reply directly to my comments, as that feature is not supported yet.

Caution

Do not close the pull request until the review is complete. Closing it early can lead to unexpected behavior and disrupt the review process.

Footnotes

  1. Rate AI review example

  2. Re-request AI review example

  3. Add AI review comments example

Comment thread src/index.js Outdated
Comment on lines 7 to 9
createServer().listen(5700, () => {
console.log('Server is running on localhost:5700');
});
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This block starts a server instance on port 5700, but another server is started later in the start function on port 3000. This is redundant and can cause issues. The server should only be started once after the database connection is successfully established. Please remove this block.

Copy link
Copy Markdown

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Summary

Excellent work on this update! You've successfully addressed all the previous feedback, particularly in correcting the server startup logic. The project now fully meets all requirements, with a complete CRUD API for categories and proper integration with PostgreSQL. Your code is clean, well-structured, and all issues from the last review have been resolved. I am happy to approve your solution. Great job!


✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨

Footnotes

  1. Rate AI review example

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants